<template>
  <div class="goods-container">
    <!-- 左侧图片区域 -->
    <div class="left">
      <img
        src="https://yanxuan-item.nosdn.127.net/3a56a913e687dc2279473e325ea770a9.jpg"
        class="avatar"
        alt=""
      />
    </div>
    <!-- 右侧商品区域 -->
    <div class="right">
      <!-- 标题 -->
      <div class="title">{{item.name}}</div>
      <div class="info">
        <!-- 单价 -->
        <span class="price">￥{{item.price}}</span>
        <div class="btns">
          <!-- 按钮区域 -->
          <button class="btn btn-light" @click="countHandel(-1)">-</button>
          <span class="count">{{item.count}}</span>
          <button class="btn btn-light" @click="countHandel(1)">+</button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'CartItem',
 props: {
  item: {
    type: Object,
    required: true
  }
},
  methods: {
  countHandel(count){
    let item=JSON.parse(JSON.stringify(this.item))
    // this.item.count+=count
    // let count=this.item.count+count
    item.count+=count
    if(item.count<1)return
    this.$store.dispatch('cart/getCount',{id:item.id,count:item.count})
  }

  }
}
</script>

<style lang="less" scoped>
.goods-container {
  display: flex;
  padding: 10px;
  + .goods-container {
    border-top: 1px solid #f8f8f8;
  }
  .left {
    .avatar {
      width: 100px;
      height: 100px;
    }
    margin-right: 10px;
  }
  .right {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    flex: 1;
    .title {
      font-weight: bold;
    }
    .info {
      display: flex;
      justify-content: space-between;
      align-items: center;
      .price {
        color: red;
        font-weight: bold;
      }
      .btns {
        .count {
          display: inline-block;
          width: 30px;
          text-align: center;
        }
      }
    }
  }
}

.custom-control-label::before,
.custom-control-label::after {
  top: 3.6rem;
}
</style>
